#!/usr/bin/env python2.7
#-*- coding:utf-8 -*-
#Author='He Rensheng'
#Email='hrs323@126.com'

import cv2

pts = []
draw = False


"""
针对一张图片, 获得鼠标点击点的坐标. 鼠标左击表示打点, 右击表示结束
"""


def on_mouse(event, x, y, flags, param):
    if event == cv2.EVENT_FLAG_LBUTTON:
        pts.append([x, y])
    if event == cv2.EVENT_FLAG_RBUTTON:
        draw = True


cv2.namedWindow("img")
cv2.setMouseCallback("img", on_mouse)


img = cv2.imread("/home/hrs/PycharmProjects/tools/GetImages/mp4_cap/192.168.0.64_01_20180718155418211-0001.jpg")
while 1:
    cv2.imshow("img", img)
    if cv2.waitKey(10) & 0xFF == ord('q'):
        break
    print("len:{}".format(pts))

for pt in pts:
    print("pt: {}".format(pt[0], pt[1]))

# # 计算相对坐标
# relative_pts = []
# for pt in pts:
#     relative_pts.append([float(pt[0])/img.shape[1], float(pt[1])/img.shape[0]])
# print("relative pts:{}".format(relative_pts))
#　计算bbox的坐标
# tx=float(bbox[0])/img.shape[1];
# ty=float(bbox[1])/img.shape[0]
# lx=float(bbox[0]+bbox[2])/img.shape[1]
# ly=float(bbox[1]+bbox[3])/img.shape[0]

cv2.destroyAllWindows()